package com.naiterui.ehp.bs.doctor.dao.impl;

import com.naiterui.ehp.bp.domain.charge.DrServiceItems;
import com.naiterui.ehp.bs.doctor.dao.IDrServiceItemsDao;
import com.naiterui.ehp.bs.doctor.repository.IDrChargeItemsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 医生开启的收费项目持久层接口
 *
 * @author Amber
 * @since 1.0.0
 */
@Component
public class AdDrChargeItemsDaoImpl implements IDrServiceItemsDao {

    @Autowired
    private IDrChargeItemsRepository drChargeItemsRepository;

    @Override
    public void saveOrUpdate(DrServiceItems drChargeItems){
        if(drChargeItems.getId() == null){
            drChargeItemsRepository.save(drChargeItems);
        } else {
            drChargeItemsRepository.update(drChargeItems);
        }
    }

    @Override
    public DrServiceItems getDoctorChargeItems(Long doctorId) {
        List<DrServiceItems> serviceItems = drChargeItemsRepository.findByDoctorId(doctorId);
        return serviceItems.size() > 0 ? serviceItems.get(0) : null;
    }


}
